package com.elvt.server.controller;


import com.elvt.server.pojo.EmployeeTrain;
import com.elvt.server.service.IEmployeeTrainService;
import com.elvt.server.utils.RespPageUtil;
import com.elvt.server.utils.RespSult;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 作者：elvt
 * @since 2022-05-21
 */
@RestController
@RequestMapping("/personnel/train/employee-train")
public class EmployeeTrainController {
    @Autowired
    public IEmployeeTrainService employeeTrainService;
    @ApiOperation(value = "获取所有员工培训")
    @GetMapping
    public RespPageUtil findAllEmpTrainByPage(@RequestParam(defaultValue = "1") Integer currentPage, @RequestParam(defaultValue = "10") Integer size  ){
       return employeeTrainService.findAllEmpTrainByPage(currentPage,size);
    }

    @ApiOperation(value = "新增员工培训")
    @PostMapping
    public RespSult save(@RequestBody EmployeeTrain employeeTrain){
        if (employeeTrainService.save(employeeTrain)){
            return RespSult.success("添加成功！") ;
        }
       return RespSult.error("添加失败");
    }
    @ApiOperation(value = "删除单个员工培训")
    @DeleteMapping("/{id}")
    public RespSult deleteById(@PathVariable Integer id){
        if (id==null){
            return RespSult.error("数据有误");
        }
        if (employeeTrainService.removeById(id)) {
            return RespSult.success("删除成功！！");

        }
        return RespSult.error("删除失败！！");
    }
    @ApiOperation("批量删除员工")
    @DeleteMapping
    public RespSult deleteByIds(Integer[] ids){
        if (ids.length<1 ){
            return RespSult.error("数据错误，请重试");
        }
        if (employeeTrainService.removeByIds(Arrays.asList(ids))) {
           return RespSult.success("批量删除成功！");
        }
        return RespSult.error("删除失败！！");
    }
}
